package com.mgang.web.controller;

import java.util.HashMap;
import java.util.Map;

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.kit.PathKit;
import com.jfinal.upload.UploadFile;
import com.mgang.model.User;
import com.mgang.util.log.MgLog;
import com.mgang.validator.UserValidator;

public class ParamController extends Controller{

	public void p1(){
		MgLog.log.info("param0:"+getPara(0)+"--param1:"+getPara(1)+"--param2:"+getPara(2));
		//setAttr("v0", getPara(0));
		Map<String, Object> p = new HashMap<String, Object>();
		p.put("v0", getPara(0));
		p.put("v1", getPara(1));
		p.put("v2", getPara(2));
		setAttrs(p);
		renderJsp("/fclient/p1.jsp");
	}
	@Before(UserValidator.class)
	public void checkUser(){
		Map<String, Object> p = new HashMap<String, Object>();
		p.put("name", getPara("name"));
		p.put("pwd", getPara("pwd"));
		setAttrs(p);
		renderJsp("/fclient/checkUser.jsp");
	}
	
	public void upload(){
		MgLog.log.info("webRootPath:"+PathKit.getWebRootPath());
		UploadFile upFile = getFile("uploadFile", PathKit.getWebRootPath() + "/temp");
		setAttr("filename", upFile.getFileName());
		renderJsp("/fclient/download.jsp");
	}
	
	public void downloadFile(){
		String filename = getPara("filename");
		MgLog.log.info("download filename is "+filename);
		renderFile("/temp/" + filename);
	}
	
	public void ajax(){
		renderJson(User.dao.findById(getParaToInt("userid")));
	}
}
